#include "LVGL_API.h"

LVGL_API_Class *LVGL_API;

void drawPoint(int x,int y,unsigned short color)
{
    QPoint p(x,y);
    int r=0;
    int g=0;
    int b=0;

    r=(color>>11)*8;
    g=((color>>5)&0x003F)*4;
    b=(color&0x001F)*8;

    QColor c(r,g,b);
    emit LVGL_API->display->goto_set_auto_pen_color(c);
    emit LVGL_API->display->goto_drawPoint(p);
}

void drawLine(int x1,int y1,int x2,int y2,unsigned short color)
{
    QPoint p1(x1,y1);
    QPoint p2(x2,y2);
    int r=0;
    int g=0;
    int b=0;

    r=(color>>11)*8;
    g=((color>>5)&0x003F)*4;
    b=(color&0x001F)*8;

    QColor c(r,g,b);
    emit LVGL_API->display->goto_set_auto_pen_color(c);
    emit LVGL_API->display->goto_drawLine(p1,p2);
}

void fillRect_drawLine(int x1,int y1,int x2,int y2)
{
    QPoint p1(x1,y1);
    QPoint p2(x2,y2);

    emit LVGL_API->display->goto_drawLine(p1,p2);
}

void fillRect(int x1,int y1,int x2,int y2,unsigned short color)
{
#if 0
    QPoint p1(x1,y1);
    QPoint p2(x2,y2);

    QPoint p3(x1,y2);
    QPoint p4(x2,y1);

    int r=0;
    int g=0;
    int b=0;

    r=(color>>11)*8;
    g=((color>>5)&0x003F)*4;
    b=(color&0x001F)*8;

    QColor c(r,g,b);
    emit LVGL_API->display->goto_set_auto_pen_color(c);
    emit LVGL_API->display->goto_drawLine(p1,p3);
    emit LVGL_API->display->goto_drawLine(p1,p4);
    emit LVGL_API->display->goto_drawLine(p2,p3);
    emit LVGL_API->display->goto_drawLine(p2,p4);
    emit LVGL_API->display->goto_fillRect(p1,p2);
#else
    int i=0;
    int r=0;
    int g=0;
    int b=0;

    r=(color>>11)*8;
    g=((color>>5)&0x003F)*4;
    b=(color&0x001F)*8;

    QColor c(r,g,b);
    emit LVGL_API->display->goto_set_auto_pen_color(c);

    for(i=0;i<=y2-y1;i++)
    {
        fillRect_drawLine(x1,y1+i,x2,y1+i);
    }
#endif
}

void Init_LVGL_API(MY_Display *dis)
{
    LVGL_API = new LVGL_API_Class(dis);
}
